class CustomizedForPostPaginate < WillPaginate::LinkRenderer
  protected
  def page_link(page, text, attributes = {})
    opts = @options[:params].clone.reject{|key, value| ["controller", "action", "authenticity_token"].include?(key.to_s)} rescue {}
    @template.link_to_function(text, 
        "sortable_js_4_post_args('', '#{@options[:ajax] }', '#{url_for(page)}', #{opts.merge(:page => page).to_json})" ,
    attributes
    )
  end
  
  def url_for(page)
    page_one = page == 1
    unless @url_string and !page_one
      @url_params = {}
      stringified_merge @url_params, @template.params if @template.request.get?
      stringified_merge @url_params, @options[:params] if @options[:params]
      if complex = param_name.index(/[^\w-]/)
        page_param = parse_query_parameters("#{param_name}=#{page}")
        stringified_merge @url_params, page_param
      else
        @url_params[param_name] = page_one ? 1 : 2
      end
      url = @template.url_for(@url_params.delete_if{|key, value| !["controller", "action"].include?(key.to_s)})
      return url
    end    
    @url_string.sub "\0", page.to_s
  end
end